package edu.cornell.cs4740.qa.baseline;

import java.util.ArrayList;
import java.util.List;

import edu.cornell.cs4740.qa.Document;
import edu.cornell.cs4740.qa.Question;
import edu.cornell.cs4740.qa.Sentence;
import edu.cornell.cs4740.qa.utilities.Util;

public class Baseline {

	Question q; // current question to answer
	List<Document> relevant_docs; // documents relevant question in rank order

	public Baseline(Question q, List<Document> docs) {
		this.q = q;
		relevant_docs = docs;
	}

	public List<Answer> answerQuestion() {
		List<Answer> as = new ArrayList<Answer>();

		Sentence s = q.questionWithoutIrrelevantWords();
		for (Document d : relevant_docs) {
			for (Sentence sen : d.getSentences()) {
				if (Util.sentenceContainsQueryWord(sen, s, false)) {
					String temp = sen.toString(10);
					boolean doesntAlreadyExist = true;
					for (Answer a : as) {
						doesntAlreadyExist &= (!a.getAnswerText().equals(temp));
					}
					if (doesntAlreadyExist) {
						as.add(new Answer(q.getQuestionNumber(), d.getDocId(),
								temp));
						if (as.size() == 5)
							return as;
					}
				}
			}
		}

		return as;
	}
}